<?php

class ClientLogSender {
	public function send($str)	{
		$opts = array
		(
			'http' => array
			(
			'method' => 'POST',
			'header'=> "Content-type: application/x-www-form-urlencoded\r\n" .
			"Content-Length: " . strlen($str) . "\r\n",
			'content' => $str,
			),
		);
		$context = stream_context_create($opts);
		$respone = file_get_contents("http://rt5.mo.baidu.mobi:10000/phone/uplog.gbza?", false, $context);
		return $respone;
	}
	
	public function generateData($arrSeq)	{
		$strData = "";
		foreach ( $arrSeq  as $value) {
			$tmp = pack("C1V1",$value['t'],$value['v']);
			$strData .= $tmp;
		}
		
		$DataLen  = strlen($strData);
		$BlockLen = $DataLen + 4;
		$BlockHeader = pack("C2v1",0x01,0x01,$BlockLen);
		$BlockData = $BlockHeader . $strData;
		$BlockData = gzencode($BlockData);
		
		$uploadLen = strlen($BlockData) + 12;
		$uploadHeader = pack("V3",28,$uploadLen,0);
		return $uploadHeader.$BlockData;
	}
}

$sender = new ClientLogSender();

$str = "";
$arrSeq = array(
	array('t'=>0x00, 'v'=>100),
	
	array('t'=>0x05, 'v'=>100),
	
	array('t'=>0x11, 'v'=>100),
	
	array('t'=>0x14, 'v'=>100),
	
	array('t'=>0x1b, 'v'=>100),
	
	array('t'=>0x21, 'v'=>100),
	array('t'=>0x22, 'v'=>100),
	array('t'=>0x23, 'v'=>100),
	array('t'=>0x24, 'v'=>100),
	array('t'=>0x25, 'v'=>100),
	array('t'=>0x26, 'v'=>100),
	array('t'=>0x27, 'v'=>100),
	array('t'=>0x28, 'v'=>100),
	array('t'=>0x29, 'v'=>100),
);

$str = $sender->generateData($arrSeq);
$respone = $sender->send($str);
echo $respone;